#include "stm32f10x.h"                  // Device header
#include "OLED.h"
#include "LED.h"
#include "MyRTC.h"
#include "Delay.h"

int main(void)
{
	OLED_Init();
	LED_Init();
	MyRTC_Init();
	OLED_ShowString(1,1,"CNT :");
	OLED_ShowString(2,1,"ALR :");
	OLED_ShowString(3,1,"ALRF:");
	
	// 开启停机状态所必须的PWR时钟
	RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR, ENABLE);

	uint32_t Alarm;
	Alarm = RTC_GetCounter() + 5;
	RTC_SetAlarm(Alarm);
	
	// 使用WakeUp唤醒设备
	PWR_WakeUpPinCmd(ENABLE);
	
	while(1)
	{
		// 验证程序从头开始执行, 从while的头???
		LED2_ON();
		Delay_ms(100);
		LED2_OFF();
		OLED_ShowNum(1, 6, RTC_GetCounter(), 10);
		OLED_ShowNum(2, 6, Alarm, 10);
		OLED_ShowNum(3, 6, RTC_GetFlagStatus(RTC_FLAG_ALR), 1);
		
		OLED_ShowString(4, 1, "Running");
		Delay_ms(100);
		OLED_ShowString(4, 1, "       ");
		Delay_ms(100);
		
		LED1_ON();
		Delay_ms(100);
		
		// 进入待机模式, 一般都得把外设的电也停了, 这才是极致省电模式!!!
		PWR_EnterSTANDBYMode();

	}
}
